// filename ************** Scheduler.h **************
// A periodic scheduler for the Proteus Robot Project
// Written by Paine, npaine@mail.utexas.edu
// Last updated 1/9/09

/** Feature Usage **
   
   Output Compare 2 interrupt
*/

#ifndef _SCHEDULER_H
#define _SCHEDULER_H 1

#define SCHED_DEBUG 0

#define MAX_EVENTS 15 //number of events that can be scheduled
//note: dynamic allocation would be a more graceful way to handle new events but is not yet implemented


// ************Scheduler_AddEvent**************************
// Schedule's an event to occur periodically
// Input:  fp - function pointer to run periodically
//         NOTE!: make this function as short as possible to reduce jitter
//         see the implementation of Scheduler_Init for an example of how to use this function
//
//         period_TOFs - timer overflows in period (bits 31-16 of period)
//         period_TCNTs - timer ticks in period (bits 15-0 of period)
// Output: 0 if successful (there is room), 1 if unsuccessful (MAX_EVENTS needs to be increased)
unsigned char Scheduler_AddEvent(void(*fp)(void), unsigned short period_TOFs, unsigned short period_TCNTs);

// ************Scheduler_RemoveEvent**************************
// Remove an event
// Input:  fp - sanme as AddEvent
//         NOTE: if two events use the same fp the first one will be removed
// Output: 0 if successful, 1 if unsuccessful (fp doesnt exist)
unsigned char Scheduler_RemoveEvent(void(*fp)(void));

// ************Scheduler_Init**************************
// Run before scheduling events
// Input:  none
// Output: none
void Scheduler_Init(void);

#if SCHED_DEBUG
// ************Scheduler_PrintEvents**************************
// Prints event info to SCI port 0
// Input:  none
// Output: none
void Scheduler_PrintEvents(void);
#endif

#endif //_SCHEDULER_H
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
        
  